package com.hh.db.entity

import com.hh.base.util.ext.toJsonString
import com.hh.base.util.ext.toModel
import com.hh.base.util.ext.toShow
import io.objectbox.annotation.Convert
import io.objectbox.annotation.Entity
import io.objectbox.annotation.Id
import io.objectbox.annotation.Transient
import io.objectbox.converter.PropertyConverter
import java.util.Date

/**
 * Create By hHui on 2025/4/16 9:14
 *
 * @description
 */
@Entity
class TODODetail {
    @Id
    var id: Long = 0

    /**
     * 所属事项id
     */
    var itemId: Long = 0

    /**
     * 事项名称
     */
    var itemName: String = ""

    /**
     * 每日的第N次
     */
    var sort: Int = 1

    /**
     * 所属事项
     */
    @Convert(converter = TODOItemConverter::class, dbType = String::class)
    var item: TODOItem = TODOItem()

    /**
     * 执行时间
     */
    var executeAt: String? = null

    /**
     * 待执行日期 2025-04-16
     */
    var toExecuteDay: String = ""

    /**
     * 创建时间
     */
    var createAt: String = Date().toShow()

    class TODOItemConverter : PropertyConverter<TODOItem, String> {
        override fun convertToEntityProperty(databaseValue: String): TODOItem {
            return databaseValue.toModel(TODOItem::class.java)
        }

        override fun convertToDatabaseValue(entityProperty: TODOItem?): String {
            return entityProperty.toJsonString()
        }

    }
}